package com.lyj.io.module.data.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyj.io.common.utils.DateUtil;
import com.lyj.io.common.utils.PageUtils;
import com.lyj.io.common.utils.Query;
import com.lyj.io.module.data.dao.TabsDao;
import com.lyj.io.module.data.entity.TabsEntity;
import com.lyj.io.module.data.service.TabsService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 模型相关接口
 * @author: 李亚杰
 * @version: 1.0
 * @date: 2021/8/19 14:31
 */
@Service("TabsService")
public class TabsServiceImpl extends ServiceImpl<TabsDao, TabsEntity> implements TabsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<TabsEntity> queryWrapper = new QueryWrapper<TabsEntity>();
        queryWrapper.eq("delete_flag", "0");
        IPage<TabsEntity> page = this.page(
                new Query<TabsEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils(page);
    }

    @Override
    public TabsEntity getById(Long id) {
        QueryWrapper<TabsEntity> queryWrapper = new QueryWrapper<TabsEntity>();
        queryWrapper.eq("id", id);
        queryWrapper.eq("delete_flag","0");
        return this.baseMapper.selectOne(queryWrapper);
    }

    @Override
    public void removeByIds(List<String> tabsIds) {
        UpdateWrapper<TabsEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", tabsIds);
        updateWrapper.set("delete_flag", DateUtil.format2String(DateUtil.YYYYMMDDHHMMSS, new Date()));
        this.baseMapper.update(null ,updateWrapper);
    }

    @Override
    public List<Map<String, Object>> queryTable(String tableName) {
        QueryWrapper<TabsEntity> queryWrapper = new QueryWrapper<TabsEntity>();
        queryWrapper.eq("tab_name", tableName);
        queryWrapper.eq("deleteFlag","0");
        List<Map<String, Object>> tabsEntity = this.baseMapper.selectMaps(queryWrapper);
        return tabsEntity;
    }

}
